package com.bing.utils;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by kaibb on 16-1-3.
 */
public abstract class JsoupUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(JsoupUtil.class);
    private static final int TIMEOUT = 5 * 1000;
    private static final String USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/44.0.2403.89 Chrome/44.0.2403.89 Safari/537.36"; //模拟浏览器User-Agent
    private static final String REFER = "http://www.google.com";


    public static Document getDocument(String url) {
        LOGGER.debug("下载数据URL:{}", url);
        Document document = null;
        try {
            document = Jsoup.connect(url).userAgent(USER_AGENT).referrer(REFER).timeout(TIMEOUT).get();
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("下载数据{}时出错", url, e);
        }
        return document;
    }
}
